import threading
import yaml



class InstConfig(object):

    _instance_lock = threading.Lock()
    _config_data = None

    def __init__(self, *args, **kwargs):
        if InstConfig._config_data:
            return 
        if len(args) < 1:
            raise AssertionError('config file not specified!')

        config_file = args[0]
        with open(config_file, 'r') as f:
            TesterConfig._config_data = yaml.safe_load(f)
            TesterConfig._has_data = True

    def __new__(cls, *args, **kwargs):
        if not hasattr(cls, '_instance'):
            with InstConfig._instance_lock:
                if not hasattr(cls, '_instance'):
                    TesterConfig._instance = super().__new__(cls)

        return InstConfig._instance

    def get_config(cls):
        return InstConfig._config_data    

        